import produce from "immer";

const initState={
  size:localStorage.getItem("size")||"middle",
  lang:localStorage.getItem("lang")||"zh",
  color:localStorage.getItem("color")||"#1890ff"
}

function reducer(state=initState,{type,payload}){
  return produce(state,(newState)=>{
    switch(type){
      case "APP_SIZE":
        newState.size=payload
        localStorage.setItem("size",payload)
        break;
      case "APP_LANG":
        newState.lang=payload
        localStorage.setItem("lang",payload)
        break;
      case "APP_COLOR":
        newState.color=payload;
        localStorage.setItem("color",payload)
        break;
      default:
    }
  })
}

export default reducer;